package bagu.juc.lock;

import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

public class LockOrderDemo {
    private ReentrantLock lock = new ReentrantLock(true);

    public void criticalSection() {
        String name = Thread.currentThread().getName();
        lock.lock();
        try {
            System.out.println(name + "-> acquired lock");
            Thread.sleep(100);
            System.out.println(name + "-> released lock");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            lock.unlock();
        }
    }


}
